/* Copyright (C) 2007 Ryan Capote
 * This file is apart of BlueEngine
 * See licsense.txt
 */

#include "timer.h"

#if defined(WIN32) || defined(WIN64)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <time.h>
#include <sys/time.h>
#endif

namespace BlueEngine
{

     namespace Utilities
     {

          void Timer::startTimer()
          {
               if( !m_running )
               {	
                    m_running = true;
                    m_starttime = getRealTime();
               }
          }
		
          void Timer::stopTimer()
          {
               m_running = false;
               m_time = getRealTime() - m_starttime;
          }
		
          void Timer::resetTimer()
          {
               m_starttime = getRealTime();
          }

          int Timer::getTime()
          {
               if( m_running )
               {
                    return ( getRealTime() - m_starttime );
               }
               else
               {
                    return m_time;
               }
          }
		
#if defined(WIN32) || defined(WIN64)
        
          int Timer::getRealTime()
          {
               return GetTickCount();
          }

#else

		  int Timer::getRealTime()
          {
               static timeval tv;
               gettimeofday(&tv, 0);
               return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
          }

#endif

     }
	
}

